import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthenticationService } from '../_services/authemtication.service';


@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  model: any = {};
  loading = false;
  error = '';
  constructor(private router: Router, private authenticationService: AuthenticationService) { }

  ngOnInit() {
    console.log(this.authenticationService.logout());
  }

  login() {
    this.loading = true;
    this.authenticationService.login(this.model.username, this.model.password)
        .subscribe(result => {
          if(result === true){
              this.router.navigate(['/']);
              alert(1);
          }else{
              this.error = "username or password is incorrent"
              this.loading = false;
              alert(2);
          }
        })
  }
}
